package edu.hawaii.senin.iclouds.basics;

import org.apache.commons.math.random.AbstractRandomGenerator;

import edu.cornell.lassp.houle.RngPack.RanMT;

/**
 * AbstractRandomGenerator based on RngPack RanMT generator. the RanMT I took from
 * http://www.honeylocust.com/RngPack/.
 * 
 * @author Pavel Senin.
 */
public class RngPackGenerator
    extends AbstractRandomGenerator {

  /**
   * Holds the random generator instance.
   */
  private RanMT random = new RanMT();

  /**
   * Sets the seed for this generator.
   * 
   * @param seed the seed value to set.
   */
  public void setSeed(long seed) {
    random = new RanMT(seed);
  }

  /**
   * Reports next random double value.
   * 
   * @return next random double value.
   */
  public double nextDouble() {
    return random.raw();
  }

  /**
   * Reports next random double value from Gaussian distribution.
   * 
   * @return next random double value from Gaussian distribution.
   */
  public double nextGaussian() {
    return random.gaussian();
  }

  /**
   * Reports next integer random number.
   * 
   * @param n the range for sampling, [0,n].
   * @return next integer random value.
   */
  public int nextInt(int n) {
    return random.choose(n);
  }

  /**
   * Reports next random boolean.
   * 
   * @return next random boolean.
   */
  public boolean nextBoolean() {
    return random.coin();
  }
}